import request from '@/utils/request'
/**
 * 获取文章列表
 * @param {*} id
 * @param {*} timestamp
 * @returns
 */
export function getArticleList (id, timestamp) {
  // console.log(id)
  return request({
    method: 'get',
    url: '/v1_1/articles',
    params: {
      channel_id: id,
      timestamp,
      with_top: 1
    }
  })
}
/**
 *对文章不喜欢
 * @param {*} target 文章id
 * @returns
 */
export const dislikeArtical = target => {
  // console.log(target)
  return request({
    method: 'POST',
    url: '/v1_0/article/dislikes',
    data: {
      target
    }
  })
}
/**
 *举报文章违规
 * @param {*} id 文章id
 * @param {*} type 举报类型
 * @returns
 */
export const reportArticle = (id, type) => {
  return request({
    method: 'post',
    url: '/v1_0/article/reports',
    data: {
      target: id,
      type
    }
  })
}
/**
 * 获取文章详情
 * @param {*} id 文章id
 * @returns
 */
export const getArticleDetail = id => {
  return request({
    method: 'get',
    url: '/v1_0/articles/' + id
  })
}
/**
 * 关注用户(作者)
 * @param {*} id 用户id
 * @returns
 */
export const followUser = id => {
  return request({
    method: 'post',
    url: '/v1_0/user/followings',
    data: {
      target: id
    }
  })
}
/**
 * 取消关注用户
 * @param {*} id
 * @returns
 */
export const unfollowUser = id => {
  return request({
    method: 'DELETE',
    url: '/v1_0/user/followings/' + id
  })
}
/**
 * 对文章点赞
 * @param {*} id 文章id
 * @returns
 */
export const addLike = id => {
  return request({
    method: 'post',
    url: '/v1_0/article/likings',
    data: {
      target: id
    }
  })
}
/**
 * 取消文章点赞
 * @param {*} id 文章id
 * @returns
 */
export const cancelLike = id => {
  return request({
    method: 'DELETE',
    url: '/v1_0/article/likings/' + id
  })
}
/**
 *对文章不喜欢
 * @param {*} id 文章id
 * @returns
 */
export const addDisLike = id => {
  return request({
    method: 'post',
    url: '/v1_0/article/dislikes',
    data: {
      target: id
    }
  })
}
/**
 * 取消对文章不喜欢
 * @param {*} id 文章id
 * @returns
 */
export const cancelDisLike = id => {
  return request({
    method: 'DELETE',
    url: '/v1_0/article/dislikes/' + id
  })
}
/**
 * 获取文章评论
 * @param {*} id 文章id
 * @returns
 */
export const getComments = (id, offset) => {
  console.log(id)
  return request({
    method: 'get',
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source: id,
      offset
    }
  })
}
/**
 * 发表评论
 * @param {*} id 文章id
 * @param {*} content 评论内容
 * @returns
 */
export const addComment = (id, content) => {
  return request({
    method: 'post',
    url: '/v1_0/comments',
    data: {
      target: id,
      content
    }
  })
}
/**
 * 对评论点赞
 * @param {*} commentId 评论id
 * @returns
 */
export const addCommentZan = commentId => {
  return request({
    method: 'POST',
    url: '/v1_0/comment/likings',
    data: {
      target: commentId
    }
  })
}
/**
 * 取消点赞
 * @param {*} commentId
 * @returns
 */
export function deleteCommentZan (commentId) {
  return request({
    url: '/v1_0/comment/likings/' + commentId,
    method: 'DELETE'
  })
}
/**
 * 获取回复列表
 * @param {*} commentId
 * @param {*} offset
 * @returns
 */
export function getReplyList (commentId, offset) {
  return request({
    url: '/v1_0/comments',
    method: 'get',
    params: {
      type: 'c',
      source: commentId,
      offset
    }
  })
}
/**
 * 添加回复接口
 * @param {*} commentId
 * @param {*} content
 * @param {*} articleId
 * @returns
 */
export function addReply (commentId, content, articleId) {
  return request({
    method: 'post',
    url: '/v1_0/comments',
    data: {
      target: commentId,
      content,
      art_id: articleId
    }
  })
}
